<?php
class vw_NewCompaniesModel extends BaseModel implements Model {
    const ST_COMPANYMAIL = 1;
    const ST_BULKMAIL = 2;
    const ST_NEWSLETTER = 3;

    function __construct() {
        parent::__construct("vw_newcompanies", "id");
        $this->addField("id", Model::TYPE_INT, Model::MOD_PRIMARY);
        $this->addField("companyname", Model::TYPE_INT);
        $this->addField("email1", Model::TYPE_INT);
        $this->addField("email2", Model::TYPE_DATE);
        $this->addField("state", Model::TYPE_INT);
    }

    public function renderAlias($record) {
        $result = $record;
        return $result;
    }
    public function getcompanyEmails($count) {
        $query = "SELECT id, companyname, email1 as email, email2 FROM vw_newcompanies WHERE state is null LIMIT 0, $count";
        $res = Database::executeQuery($query);
        $result = Database::getDataFromResource($res);
        return $result; 
    }

    public function setState($id, $state) {
        $query = QueryHelper::update("extracompanies", array(
            state => $state,
        ), "id=$id");
        Database::executeQuery($query);
    }

    public function getList() {
        return $this->loadAll("state is null");
    }

    public function isAuthorized($operation, $subject = "") {
        return true;
//        if (Auth::isAdmin()) { return true; }
/*
        switch ($operation) {
            case "update" :
            case "delete" :
            case "addnew" : {
                if (Auth::canChangeDrivers()) { return true; }
            }
            case "list" : {
                if (Auth::canListDrivers()) { return true; }
            }
        }
        return false;
*/
    }

    public function modifyDatabaseInput($data) {
        return $data;
    }
}

?>
